/*
 * Copyright (C) hushenglan
 */

#ifndef _MYSYS_PROCESS_H_
#define _MYSYS_PROCESS_H_

namespace mysys
{

typedef pid_t ms_pid_t;
typedef int (*process_main_pt)(void *args);
typedef void (*process_exit_pt)(void);

class CProcess
{
public:

    /*
     * 构造函数
     */
    CProcess(process_main_pt routine, void *args);

    /*
     * 析构函数
     */
    virtual ~CProcess();

    /*
     * 守护进程
     */
    int daemon();

    /*
     * 启动进程
     */
    int start();

    /*
     * 进程main函数
     */
    int processMain();

    /*
     * 设置进程退出的动作
     */
    int setAtexit(process_exit_pt func);

    /*
     * 获取进程id
     */
    ms_pid_t getPid();

private:

    process_main_pt _routine;
    void *_args;
};

}

#endif
